package net.zoneland.knowledge.config;

import com.branchitech.commons.time.biz.IComplexWorkDayCache;
import com.branchitech.commons.time.biz.IComplexWorkDayHandler;
import com.branchitech.commons.time.biz.impl.ComplexWorkDayCacheEhImpl;
import com.branchitech.commons.time.biz.impl.ComplexWorkDayHandlerImpl;
import com.branchitech.commons.time.biz.impl.WorkTimeHandlerDefaultImpl;
import com.branchitech.commons.time.util.HolidayUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * .
 *
 * @author: bcc
 * 2020/9/17
 */
@Configuration
public class WorkDayConfig {

    @Value("${holiday.url}")
    private String holidayUrl;

    @Bean
    public IComplexWorkDayHandler iWorkDay() {
        IComplexWorkDayHandler workday = new ComplexWorkDayHandlerImpl();
        //缓存实现
        IComplexWorkDayCache cache = new ComplexWorkDayCacheEhImpl();
        //设置缓存
        workday.setComplexWorkDayCache(cache);

        //缓存存活时间  默认1200秒
        HolidayUtil.setCacheLiveSecond(12000);
        //节假日配置是否独立 默认独立
        HolidayUtil.setIsolation(true);
        HolidayUtil.setUrl(holidayUrl);
        WorkTimeHandlerDefaultImpl.getInstance().workStartTime = 0;
        WorkTimeHandlerDefaultImpl.getInstance().workEndTime = 24L * 3600 * 1000;
        return workday;
    }
}
